home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / flow3.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  152 lines

  1. ; $Id: flow3.pro,v 1.4 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. pro blob3, x0, y0, z0        ;Draw a blob at (x0, y0, z0) (may be arrays)
  8. n = n_elements(x0)-1
  9.  
  10. hfact = .010        ;Size of heads
  11. u = 1./[!x.s[1], !y.s[1],!z.s[1]] * hfact    ;Size in data coords
  12. u0 = [[1,0,0],[0,1,0],[0,0,1]]    ;Directions
  13. for i=0,n-1 do begin
  14.     p0 = [ x0[i], y0[i], z0[i]]
  15.     for j=0,2 do begin
  16.         v = u * u0[*,j]
  17.         plots,[[p0+v],[p0-v]],/T3D
  18.         endfor
  19.     endfor
  20. end
  21.  
  22.  
  23. pro arrow3, x0, y0, z0, x1, y1, z1, flags, arrowsize
  24. ; Draw an arrow-head at the
  25. ; ends of vectors (x0,y0,z0) to (x1, y1, z1).  Params may be arrays.
  26. ; Flags(i) = 1 to draw head at end of ith vector.
  27. ;
  28. dx = x1-x0
  29. dy = y1-y0
  30. dz = z1-z0
  31. zz = sqrt(dx^2 + dy^2 + dz^2) > 1e-6    ;Length
  32.  
  33.  
  34. dx = dx/zz        ;Cos th
  35. dy = dy/zz        ;Sin th
  36.  
  37. u0 = [-.866/!x.s[1], -.5/!y.s[1], 0]*arrowsize    ;Arrow head vectors (XY plane)
  38. u1 = [-.866/!x.s[1],  .5/!y.s[1], 0]*arrowsize
  39.  
  40. n = n_elements(x0)-1
  41.  
  42. for i=0,n-1 do if flags[i] then begin    ;Heads?
  43.     xx = x1[i]
  44.     yy = y1[i]
  45.     zz = z1[i]
  46.     dx0 = dx[i]
  47.     dy0 = dy[i]
  48.     xx0 = xx + dx0*u0[0] - dy0 * u0[1]
  49.     yy0 = yy + dx0*u0[1] + dy0 * u0[0]
  50.     xx1 = xx + dx0*u1[0] - dy0 * u1[1]
  51.     yy1 = yy + dx0*u1[1] + dy0 * u1[0]
  52.     plots, [xx0,xx,xx1],[yy0,yy,yy1],[zz,zz,zz],/t3d
  53.     endif
  54. end
  55.  
  56.  
  57. pro flow3, vx, vy, vz, nvecs=nvecs, nsteps = nsteps, len = len, blob=blob, $
  58.     sx = sx, sy = sy, sz = sz, arrowsize = arrowsize
  59. ;+
  60. ; NAME:
  61. ;    FLOW3 - Draw 3D flow/velocity field.
  62. ; PURPOSE:
  63. ;    Draw lines representing a 3D flow/velocity field.
  64. ; CATEGORY:
  65. ;    Graphics.
  66. ; CALLING SEQUENCE:
  67. ;    FLOW3, vx, vy, vz
  68. ; INPUTS:
  69. ;    Vx, Vy, Vz = 3D arrays containing X, Y, and Z components
  70. ;        of the field.
  71. ; KEYWORD PARAMETERS:
  72. ;    Sx, Sy, Sz = Optional vectors containing the starting coordinates
  73. ;      of the flow lines. If omitted random starting points are chosen.
  74. ;    Nvecs = Number of random flow lines to draw (Default = 200).
  75. ;      Only used if Sx, Sy, Sz are not present.
  76. ;    Len = Length of each step used to follow flow lines.  Default = 2.0
  77. ;      Expressed in units of largest field vector, i.e. the length of
  78. ;      the longest step is set to len times the grid spacing.
  79. ;    Nsteps = number of steps used to follow the flow lines.  Default =
  80. ;      largest dimension of vx / 5.
  81. ;    Blob = 1 to draw a blob at the beginning of each flow line and
  82. ;      suppress the arrows.
  83. ;    Arrowsize = size of arrowheads, default = 0.05
  84. ; OUTPUTS:
  85. ;    None.  Graphics are produced on the currently selected graphics
  86. ;    device.
  87. ; COMMON BLOCKS:
  88. ;    None.
  89. ; RESTRICTIONS:
  90. ;    Works best with Z buffer output device.
  91. ; PROCEDURE:
  92. ;    The 3D scaling system must be set before calling this procedure.
  93. ;    For example:  scale3, xr=[0,nx-1], yr=[0,ny-1], zr = [0,nz-1]
  94. ;    where nx, ny, and nz are the 1st, 2nd, and 3rd dimensions of
  95. ;    VX, VY, and VZ.
  96. ; MODIFICATION HISTORY:
  97. ;    DMS - RSI, Nov, 1991.
  98. ;-
  99.  
  100.  
  101.  
  102. s = size(vx)
  103. if s[0] ne 3 then message,'FLOW3: Vx, Vy, and Vz must be 3D arrays'
  104. nx = s[1]
  105. ny = s[2]
  106. nz = s[3]
  107. if n_elements(nsteps) le 0 then nsteps = (nx > ny > nz) /5
  108.  
  109. if n_elements(sx) le 0 then begin    ;Starting points specified?
  110.     if n_elements(nvecs) le 0 then nvecs = 200
  111.     x1 = randomu(seed, nvecs) * (nx-1)
  112.     y1 = randomu(seed, nvecs) * (ny-1)
  113.     z1 = randomu(seed, nvecs) * (nz-1)
  114. endif else begin
  115.     x1 = float(sx)
  116.     y1 = float(sy)
  117.     z1 = float(sz)
  118.     nvecs = n_elements(x1) < n_elements(y1) < n_elements(z1)
  119. endelse
  120.  
  121. if n_elements(len) le 0 then len = 2.0  ;Default length
  122. if n_elements(arrowsize) le 0 then arrowsize = 0.05
  123.  
  124. zscale = len/max(sqrt(vx^2+vy^2+vz^2))  ;Make max step = len
  125.  
  126. ; Valid points.
  127. flags = (x1 ge 0) and (x1 le nx-1) and (y1 ge 0) and (y1 le ny-1) and $
  128.         (z1 ge 0) and (z1 le nz-1)
  129.  
  130. for i=0,nsteps do begin        ;Draw each element
  131.     x0 = x1
  132.     y0 = y1
  133.     z0 = z1
  134.     x1 = interpolate(vx, x0,y0,z0)*zscale + x0
  135.     y1 = interpolate(vy, x0,y0,z0)*zscale + y0
  136.     z1 = interpolate(vz, x0, y0, z0)*zscale + z0
  137.     flags = flags and $
  138.           (x1 ge 0) and (x1 le nx-1) and $
  139.           (y1 ge 0) and (y1 le ny-1) and $
  140.           (z1 ge 0) and (z1 le nz-1)
  141.  
  142.     if (i ne 0) or keyword_set(blob) then $
  143.        for j=0,nvecs-1 do if flags[j] then $
  144.         plots, [x0[j], x1[j]],[y0[j],y1[j]],[z0[j],z1[j]],/t3d
  145.         if keyword_set(blob) and (i eq 0) then $
  146.         blob3, x0, y0, z0
  147.     if ((i eq 0) or (i eq nsteps)) and (keyword_set(blob) eq 0) then $
  148.         arrow3, x0, y0, z0, x1, y1, z1, flags, arrowsize
  149.     endfor
  150.  
  151. end
  152.